package com.tcp.c100w.client;

import com.tcp.c100w.c100w_remoting.RemotingClient;
import com.tcp.c100w.c100w_remoting.RemotingServer;
import com.tcp.c100w.c100w_remoting.common.Pair;
import com.tcp.c100w.c100w_remoting.common.ThreadFactoryImpl;
import com.tcp.c100w.c100w_remoting.netty.NettyClientConfig;
import com.tcp.c100w.c100w_remoting.netty.NettyRemotingClient;
import com.tcp.c100w.c100w_remoting.netty.NettyRequestProcessor;
import com.tcp.c100w.c100w_remoting.protocol.RemotingCmd;
import com.tcp.c100w.client.processor.DefaultRequestProcessor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        NettyClientConfig nettyClientConfig=new NettyClientConfig();
        nettyClientConfig.setIp("127.0.0.1");
        nettyClientConfig.setListenPort(8888);
        RemotingClient  client=new NettyRemotingClient(nettyClientConfig);
        client.start();
        ExecutorService remotingExecutor = Executors.newFixedThreadPool(nettyClientConfig.getProcessosThread(),
                new ThreadFactoryImpl("RemotingExecutorThread_"));
        client.registerDefaultProcessor(new DefaultRequestProcessor(),remotingExecutor);
        RemotingCmd remotingCmd=new RemotingCmd();
        try {
            remotingCmd.setBody("test data");
            for (int i = 0; i <100 ; i++) {
                Thread.sleep(1000);
                client.invokeAsync(remotingCmd);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
